package com.hoshiicloud.as2c.minipro.feign.hystrix;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.as2c.minipro.dto.OrderDTO;
import com.hoshiicloud.as2c.minipro.dto.PayResultDTO;
import com.hoshiicloud.as2c.minipro.feign.OrderFeignService;
import com.hoshiicloud.as2c.minipro.param.*;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.validation.Valid;

/**
 * @author zhangshuhu
 * @version 1.0
 * @title: HystrixOrderFeignFallback
 * @description: 订单微服务FeignClient熔断器
 * @date 2019/6/10 0:43
 * @mail maiboyc@163.com
 */
@Slf4j
@Component
public class HystrixOrderFeignFallback implements FallbackFactory<OrderFeignService> {


    @Override
    @HystrixCommand
    public OrderFeignService create(Throwable throwable) {
        log.error("出现异常" + throwable.getMessage());
        return new OrderFeignService() {
            /**
             * 提交订单微服务异常处理
             * @param param
             * @return
             */
            @Override
            public Response submitOrder(OrderSubmitParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<PayResultDTO> payOrder(PayOrderParam param) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 取消订单微服务异常处理
             * @param orderId
             * @return
             */
            @Override
            public Response cancelOrder(@Valid Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 删除订单微服务异常处理
             * @param orderId
             * @return
             */
            @Override
            public Response deleteOrder(@Valid Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<Page<OrderDTO>> listOrder(OrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<OrderDTO> viewOrder(Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<OrderDTO> verificationOrder(Long orderId) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response<Page<OrderDTO>> listStoreOrder(StoreOrderQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response updateOrderStatus(OrderMainStatusUpdateParam param) {
                return Response.failed(throwable.getMessage());
            }

            /**
             * 多条件查询订单异常处理
             * @param param OrderMainQueryParam
             * @return Response
             */
            @Override
            public Response multiConditionQueryOrderPage(OrderMainQueryParam param) {
                return Response.failed(throwable.getMessage());
            }

            @Override
            public Response refundOrder(@Valid Long orderId) {
                return Response.failed(throwable.getMessage());
            }
        };
    }
}
